package fr.blogger.web.bean.utilitaire;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.view.ViewScoped;
import javax.inject.Named;

@Named
@ViewScoped
public class GenericConverter implements Converter, Serializable {

	private Map<UUID, Object> temporaryStore = new HashMap<UUID, Object>();

	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		return temporaryStore.get(UUID.fromString(value));
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component, Object value) {
		UUID id = UUID.randomUUID();
		temporaryStore.put(id, value);
		return id.toString();
	}

}
